#define DEBUG
#include <cstdio>
#include <cstdlib>
#define MAXN 200000

using namespace std;

int getFa(int *set, int o) {
  if (set[o]!=o) {
    set[o] = getFa(set, set[o]);
  }
  return set[o];
}

int main() {
#ifdef DEBUG
  freopen("1.in", "r", stdin);
  freopen("1.out", "w", stdout);
#endif

  static int set[MAXN+1], to[MAXN+1];
  int n;
  scanf("%d", &n);
  for (int i=1; i<=n; i++) {
    set[i] = i;
  }
  for (int i=1; i<=n; i++) {
    scanf("%d", to+i);
    if (getFa(set, i)==getFa(set, to[i])) {
      int size=1;
      for (int x=to[i]; x!=i; x=to[x], size++);
      printf("%d\n", size);
      for (int x=to[i]; x!=i; x=to[x]) {
	printf("%d ", x);
      }
      printf("%d", i);
      break;
    } else {
      set[getFa(set, i)] = getFa(set, to[i]);
    }
  }

  fcloseall();
  return 0;
}
